package com.dbpms.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;
// web配置类
public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    // 返回Spring的配置类 -> 需要SpringConfig配置类
    @Override
    protected Class<?>[] getRootConfigClasses() {
        // 加载spring核心配置
        return new Class[]{SpringConfig.class};
    }
    // 返回SpringMVC的配置类 -> 需要SpringMvcConfig配置类
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    // 设置SpringMVC请求拦截路径规则
    @Override
    protected String[] getServletMappings() {
        // 拦截所有的请求
        return new String[]{"/"};
    }

    // 设置过滤器，解决POST请求中文乱码问题
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        return new Filter[]{filter};
    }
}